/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.annuaireComp.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author MiniK
 */
@Entity
@Table(name = "competence")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Competence.findAll", query = "SELECT c FROM Competence c"),
    @NamedQuery(name = "Competence.findByIdcompetence", query = "SELECT c FROM Competence c WHERE c.idcompetence = :idcompetence"),
    @NamedQuery(name = "Competence.findByLibelle", query = "SELECT c FROM Competence c WHERE c.libelle = :libelle")})
public class Competence implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idcompetence")
    private Integer idcompetence;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "libelle")
    private String libelle;
    @Lob
    @Size(max = 65535)
    @Column(name = "description")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "competence", fetch = FetchType.EAGER)
    private List<CompetencePersonnel> competencePersonnelList;
    @JoinColumn(name = "savoir_competence", referencedColumnName = "idsavoir_competence")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private SavoirCompetence savoirCompetence;
    @JoinColumn(name = "domaine_competence", referencedColumnName = "iddomaine_competence")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private DomaineCompetence domaineCompetence;
    @OneToMany(mappedBy = "competenceMere", fetch = FetchType.EAGER)
    private List<Competence> competenceList;
    @JoinColumn(name = "competence_mere", referencedColumnName = "idcompetence")
    @ManyToOne(fetch = FetchType.EAGER)
    private Competence competenceMere;

    public Competence() {
    }

    public Competence(Integer idcompetence) {
        this.idcompetence = idcompetence;
    }

    public Competence(Integer idcompetence, String libelle) {
        this.idcompetence = idcompetence;
        this.libelle = libelle;
    }

    public Integer getIdcompetence() {
        return idcompetence;
    }

    public void setIdcompetence(Integer idcompetence) {
        this.idcompetence = idcompetence;
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public List<CompetencePersonnel> getCompetencePersonnelList() {
        return competencePersonnelList;
    }

    public void setCompetencePersonnelList(List<CompetencePersonnel> competencePersonnelList) {
        this.competencePersonnelList = competencePersonnelList;
    }

    public SavoirCompetence getSavoirCompetence() {
        return savoirCompetence;
    }

    public void setSavoirCompetence(SavoirCompetence savoirCompetence) {
        this.savoirCompetence = savoirCompetence;
    }

    public DomaineCompetence getDomaineCompetence() {
        return domaineCompetence;
    }

    public void setDomaineCompetence(DomaineCompetence domaineCompetence) {
        this.domaineCompetence = domaineCompetence;
    }

    @XmlTransient
    public List<Competence> getCompetenceList() {
        return competenceList;
    }

    public void setCompetenceList(List<Competence> competenceList) {
        this.competenceList = competenceList;
    }

    public Competence getCompetenceMere() {
        return competenceMere;
    }

    public void setCompetenceMere(Competence competenceMere) {
        this.competenceMere = competenceMere;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idcompetence != null ? idcompetence.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Competence)) {
            return false;
        }
        Competence other = (Competence) object;
        if ((this.idcompetence == null && other.idcompetence != null) || (this.idcompetence != null && !this.idcompetence.equals(other.idcompetence))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.annuaireComp.entities.Competence[ idcompetence=" + idcompetence + " ]";
    }
    
}
